package com.ja.openchat.viewmodels;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ja.openchat.databinding.ActivityGroupManagerBinding;
import com.ja.openchat.ui.chat.group.GroupChatManagerActivity;
import com.zy.openchat.core.manager.TgEvent;
import com.zy.openchat.core.model.group.SuperGroupInfo;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.base.BaseViewModel;


public class GroupChatManagerViewModel extends BaseViewModel {


    public GroupChatManagerViewModel(@NonNull Application application, BaseModel mRepository) {
        super(application);
    }
    private GroupChatManagerActivity editGroupChatActivity;
    private ActivityGroupManagerBinding binding;
    public void setContext(GroupChatManagerActivity editGroupChatActivity, ActivityGroupManagerBinding binding) {
        this.editGroupChatActivity = editGroupChatActivity;
        this.binding = binding;
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTgEvent(final TgEvent tg_event) {
        switch (tg_event.event) {
            case EUser_Td_Group_Super_Info_Changed:
                if(tg_event.data!=null&&tg_event.data instanceof SuperGroupInfo){
                    SuperGroupInfo groupInfo = (SuperGroupInfo)tg_event.data;
                    if(editGroupChatActivity.chatInfo!=null&&editGroupChatActivity.chatInfo.superGroupId() == groupInfo.id){
                        editGroupChatActivity.mSuperGroupInfo = groupInfo;
                        editGroupChatActivity.resetUI();
                    }
                }
                break;
        }

    }

}
